﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Paas.Pioneer.Admin.Core.Application.Contracts.Api;
using Paas.Pioneer.Admin.Core.Application.Contracts.Api.Dto.Input;
using Paas.Pioneer.Admin.Core.Application.Contracts.Api.Dto.Output;
using Paas.Pioneer.Domain.Shared.Dto.Input;
using Paas.Pioneer.Domain.Shared.Dto.Output;
using Volo.Abp.AspNetCore.Mvc;

namespace Paas.Pioneer.Admin.Core.HttpApi.Controllers.Api;

/// <summary>
/// 接口管理
/// </summary>
[Route("api/admin/[controller]")]
[Authorize]
public class ApiController : AbpControllerBase
{
    private readonly IApiService _apiService;

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="apiService"></param>
    public ApiController(IApiService apiService)
    {
        _apiService = apiService;
    }

    /// <summary>
    /// 查询单条接口
    /// </summary>
    /// <param name="id">主键</param>
    /// <returns></returns>
    [HttpGet("{id}")]
    public async Task<ApiGetOutput> Get(Guid id)
    {
        return await _apiService.GetAsync(id);
    }

    /// <summary>
    /// 查询全部接口
    /// </summary>
    /// <param name="key">搜索key</param>
    /// <returns></returns>
    [HttpGet("list")]
    public async Task<List<ApiListOutput>> GetList(string key)
    {
        return await _apiService.GetListAsync(key);
    }

    /// <summary>
    /// 查询分页接口(没有用使用)
    /// </summary>
    /// <param name="model">分页模型</param>
    /// <returns></returns>
    [HttpPost("page-list")]
    public async Task<Page<ApiListOutput>> GetPageList([FromBody] PageInput<ApiInput> model)
    {
        return await _apiService.GetPageListAsync(model);
    }

    /// <summary>
    /// 新增接口
    /// </summary>
    /// <param name="input">添加模型</param>
    /// <returns></returns>
    [HttpPost]
    public async Task Add([FromBody] ApiAddInput input)
    {
        await _apiService.AddAsync(input);
    }

    /// <summary>
    /// 修改接口
    /// </summary>
    /// <param name="input">修改模型</param>
    /// <returns></returns>
    [HttpPut]
    public async Task Update([FromBody] ApiUpdateInput input)
    {
        await _apiService.UpdateAsync(input);
    }

    /// <summary>
    /// 删除api
    /// </summary>
    /// <param name="id">主键</param>
    /// <returns></returns>
    [HttpDelete("{id}")]
    public async Task SoftDeleteAsync(Guid id)
    {
        await _apiService.DeleteAsync(id);
    }

    /// <summary>
    /// 批量删除数据字典
    /// </summary>
    /// <param name="ids">主键数组</param>
    /// <returns></returns>
    [HttpDelete("ids")]
    public async Task BatchSoftDelete([FromBody] Guid[] ids)
    {
        await _apiService.BatchSoftDeleteAsync(ids);
    }
}